package com.edu.exam.enums;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 通用配置状态枚举
 */
public enum ConfigStatus implements BaseEnum {
    ACTIVE("ACTIVE", "启用"),
    INACTIVE("INACTIVE", "禁用"),
    DEPRECATED("DEPRECATED", "已废弃"),
    DRAFT("DRAFT", "草稿"),
    PENDING("PENDING", "待审核"),
    APPROVED("APPROVED", "已审核"),
    REJECTED("REJECTED", "已拒绝"),
    ARCHIVED("ARCHIVED", "已归档"),
    SUSPENDED("SUSPENDED", "已暂停"),
    TESTING("TESTING", "测试中");

    private final String code;
    private final String description;

    ConfigStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static ConfigStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            return DRAFT;
        }
        for (ConfigStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown config status code: " + code);
    }

    public static ConfigStatus fromDescription(String description) {
        for (ConfigStatus status : values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown config status description: " + description);
    }
}